#!/usr/local/php/bin/php
<?php
/**
 * CLI (Command Line Interface) 入口脚本
 *
 *    使用方法：
 *    Linux/Unix     $   ./cli help
 *    Windows     c:\>   %PHPPATH/bin/php cli help
 *
 */

/**
 * 定义路径常量
 */
define('APPROOT', dirname(__FILE__).DIRECTORY_SEPARATOR);
define('LIBPATH', APPROOT.'library'.DIRECTORY_SEPARATOR);
define('MODULEPATH', APPROOT.'modules'.DIRECTORY_SEPARATOR);
define('SCRIPTPATH', APPROOT.'scripts'.DIRECTORY_SEPARATOR);

/**
 * 定义PHP扩展名
 */
define('EXT', '.php');

/**
 * 设置错误报告方式
 */
error_reporting(E_ALL | E_STRICT);

if (phpversion() >= "5.3") {
	define("APPLICATION_PATH", dirname(__DIR__));
} else {
	define("APPLICATION_PATH", dirname(dirname(__FILE__)));
}

/**
 *  Run Application
 */
try
{
	if(count($argv) < 2) {
		echo '参数错误';
		exit;
	}
	
	$params = array();
	foreach($argv as $v){
		if(preg_match('/^--([a-zA-Z]+)=([a-zA-Z1-9]+)/', $v, $m) AND count($m) == 3){
			$params[$m[1]] = $m[2];
		}
	}
	$app = new Yaf_Application(APPLICATION_PATH . "/conf/cli.ini");
	$request = new Yaf_Request_Simple("CLI", "Cli", $argv[1], "Index", $params);
	//var_dump($request);
	$app->getDispatcher()->dispatch($request);
	//$app->bootstrap()->run();
}
catch(Exception $e)
{
	echo $e->getMessage();
}
?>